import request from '@/router/axios';

export const getSignature =() => { // 获取签名
  return request({
    url: '/api/blade-file/getSignature',
    method: 'get'
  })
}


export const getTree = (parentDirPath) => { // tree树
  return request({
    url: '/api/blade-file/file/tree-list',
    method: 'post',
    params: {
      parentDirPath
    }
  })
}

export const reName = (folderName, newSrc, oldSrc, isFile, appName) => { //重命名
  return request({
    url: '/api/blade-file/file/rename-minio-object',
    method: 'post',
    params: {
      folderName,
      newSrc,
      oldSrc,
      isFile,
      appName,
    }
  })
}

export const removeFile = (fileId, filePath) => { //删除文件
  return request({
    url: '/api/blade-file/file/del-minio-file',
    method: 'post',
    params: {
      fileId,
      filePath
    }
  })
}

export const removeFolder = (folderPath) => { //删除文件夹
  return request({
    url: '/api/blade-file/file/del-minio-folder',
    method: 'post',
    params: {
      folderPath
    }
  })
}


export const copyFile = (destPath, folder, sourcePath, appName) => { //复制文件
  return request({
    url: '/api/blade-file/file/copy-minio-object',
    method: 'post',
    params: {
      destPath: destPath,
      folder,
      sourcePath,
      appName
    }
  })
}

export const copyFolder = (destDir, sourcePath, appName) => { //复制文件夹
  return request({
    url: '/api/blade-file/file/copy-minio-folder',
    method: 'post',
    params: {
      destDir, // 复制到的地址
      sourcePath, // 复制的文件原路径
      appName // 项目地址
    }
  })
}


export const uploadFile = ({file, folderName, appName}) => { //上传文件
  return request({
    url: '/api/blade-file/file/put-minio-object',
    method: 'post',
    headers: {'Content-Type': 'application/json'},
    params: {
      file,
      folderName,
      appName
    }
  })
}

export const addFileFolder = (folder, parentFolder, isshare) => { //新建文件夹
  return request({
    url: '/api/blade-file/file/add-minio-folder',
    method: 'post',
    params: {
      folder,
      parentFolder,
      isshare
    }
  })
}

export const getTabList = (parentDirPath) => { //根据左侧tree查询子节点
  return request({
    url: '/api/blade-file/file/sub-list',
    method: 'post',
    params: {
      parentDirPath
    }
  })
}

export const searchFile =(findName, parentDirPath) => { // 搜索file
  return request({
    url: '/api/blade-file/file/like-list',
    method: 'post',
    params: {
      findName,
      parentDirPath
    }
  })
}

export const newUploadFile =(data) => { // 搜索file
  return request({
    url: '/api/blade-file/file/ossUpload',
    method: 'post',
    data
  })
}

export const fireExists =(data) => { // 判断是否有重名文件
  return request({
    url: '/api/blade-file/file/exists',
    method: 'post',
    data
  })
}

export const editPreview =(cloudFileId, fileUrl) => { // 判断是否有重名文件
  return request({
    url: '/api/blade-file/file/replace',
    method: 'post',
    data:{
      cloudFileId,
      fileUrl
    }
  })
}

export const downloadFile =(fileId) => { // 判断是否有重名文件
  return request({
    url: '/api/blade-file/file/down-minio-object',
    method: 'get',
    responseType: 'blob',
    params:{
      fileId
    }
  })
}
